import {Plugin} from "vite";

/**
 * 替换掉jsp里面一些代码
 */
export function vitePluginJsp2html():Plugin {
  return {
    name: 'vite-plugin-jsp2html',
    enforce: 'pre',
    transformIndexHtml: {
      order: 'pre',
      handler(code){
        code = code.replace(/\<\%\-\-([\s\S]+?)\-\-\%\>/g,($0,$1)=>{
          return `<!--${$1}-->`
        })
        code = code.replace(/\<\%\@([\s\S]+?)\%\>/g,($0,$1)=>{
          return `<!--${$1}-->`
        })
        return code
      }
    }
  }
}
